//
//  LSDataCollectViewController.m
//  LaSaCivilAffairsDepartment
//
//  Created by 聂志康 on 2018/12/21.
//  Copyright © 2018 wpkj. All rights reserved.
//

#import "LSDataCollectViewController.h"
#import "LSInfoCollectDisplayListViewController.h"

@interface LSDataCollectViewController ()
@property (nonatomic, strong) NSArray <NSDictionary *>*contentArray;
@end

@implementation LSDataCollectViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.title = @"数据管理";
    [self setUpUI];
}

- (void)setUpUI {
    UIView *backView = [[UIView alloc] initWithFrame:CGRectMake(0, 10, ScreenWidth, 220)];
    backView.backgroundColor = UIColor.whiteColor;
    [self.view addSubview:backView];
//    [backView addSubview:[[UILabel alloc] initWithFrame:CGRectMake(15, 0, ScreenWidth-30, 22) andText:@"基础数据管理" andTextColor:hexColor(333333) andFont:[UIFont fontWithName:@"SourceHanSansCN-Regular" size:12] andTextAlignment:NSTextAlignmentLeft]];
//    UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(0, 22, ScreenWidth, 0.5)];
//    lineView.backgroundColor = hexColor(CCCCCC);
//    [backView addSubview:lineView];
    
    for (int i = 0; i < self.contentArray.count; i++) {
        UIButton *Button = [[UIButton alloc] initWithFrame:CGRectMake(25, 24+60*i, ScreenWidth-50, 50)];
        Button.tag = i+TagFoundation;
        [Button setBackgroundImage:[UIImage imageWithColor:hexColor(ffffff)] forState:UIControlStateNormal];
        [Button setBackgroundImage:[UIImage imageWithColor:hexColor(eeeeee)] forState:UIControlStateHighlighted];
        //1.设置阴影颜色
        Button.layer.shadowColor = hexColor(2D78AB).CGColor;
        //2.设置阴影偏移范围
        Button.layer.shadowOffset = CGSizeMake(1, 1);
        //3.设置阴影颜色的透明度
        Button.layer.shadowOpacity = 0.7;
        Button.layer.borderColor = hexColor(2D78AB).CGColor;
        Button.layer.borderWidth = 0.5;
        Button.titleLabel.font = [UIFont fontWithName:@"SourceHanSansCN-Regular" size:17];
        [Button setImage:[UIImage imageNamed:self.contentArray[i][@"image"]] forState:UIControlStateNormal];
        [Button setTitle:self.contentArray[i][@"title"] forState:UIControlStateNormal];
        [Button setTitleColor:hexColor(2D78AB) forState:UIControlStateNormal];
        [Button setTitleEdgeInsets:UIEdgeInsetsMake(0, 20, 0, 0)];
        [Button setImageEdgeInsets:UIEdgeInsetsMake(0, 0, 0, 20)];
        [Button addTarget:self action:@selector(ButtonClick:) forControlEvents:UIControlEventTouchUpInside];
        [backView addSubview:Button];
        CGRect TitleRect = [self.contentArray[i][@"title"] boundingRectWithSize:CGSizeMake(ScreenWidth-50, 0) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName : [UIFont fontWithName:@"SourceHanSansCN-Regular" size:17]} context:nil];
        UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake((ScreenWidth-50-TitleRect.size.width)*0.5+12, 11, 1, 50-22)];
        lineView.backgroundColor = hexColor(2D78AB);
        [Button addSubview:lineView];
    }
}

- (void)ButtonClick:(UIButton *)button {
    NSInteger tag = button.tag-TagFoundation;
    LSInfoCollectDisplayListViewController *infoCollectDisplayListVC = [[LSInfoCollectDisplayListViewController alloc] init];
    switch (tag) {
        case 0:
        {
            infoCollectDisplayListVC.title = @"老龄人员基础数据管理";
            infoCollectDisplayListVC.searchPlaceholder = @"请输入姓名";
            infoCollectDisplayListVC.URLString = LSAgeingList;
            infoCollectDisplayListVC.contentZiDuanArray = @[@"name",@"sex",@"cardNo"];
            infoCollectDisplayListVC.displayTag = 0;
        }
            break;
        case 1:
        {
            infoCollectDisplayListVC.title = @"社工人员基础数据管理";
            infoCollectDisplayListVC.searchPlaceholder = @"请输入姓名";
            infoCollectDisplayListVC.URLString = LSSocialWorkerlist;
            infoCollectDisplayListVC.contentZiDuanArray = @[@"name",@"sex",@"idCard"];
            infoCollectDisplayListVC.displayTag = 1;
        }
            break;
        case 2:
        {
            infoCollectDisplayListVC.title = @"留守儿童基础数据管理";
            infoCollectDisplayListVC.searchPlaceholder = @"请输入要查询的姓名：例如_张三";
            infoCollectDisplayListVC.URLString = LSLcimsList;
            infoCollectDisplayListVC.contentZiDuanArray = @[@"name",@"gender",@"idcard"];
            infoCollectDisplayListVC.displayTag = 2;
        }
            break;
        default:
            break;
    }
    [self.navigationController pushViewController:infoCollectDisplayListVC animated:true];
}

- (NSArray<NSDictionary *> *)contentArray {
    if (!_contentArray) {
        _contentArray = @[@{@"image":@"icon5_xxcj",@"title":@"老龄人员基础数据管理"},
                          @{@"image":@"icon6_xxcj",@"title":@"社工人员基础数据管理"},
                          @{@"image":@"icon7_xxcj",@"title":@"留守儿童基础数据管理"}];
    }
    return _contentArray;
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
